package cn.xq.pethome.sysDicTail.controller;

import cn.xq.pethome.sysDicTail.domain.DicTail;
import cn.xq.pethome.sysDicTail.query.DicTailQuery;
import cn.xq.pethome.sysDicTail.service.LDicTailService;
import cn.xq.pethome.sysDictType.domain.Dictype;
import cn.xq.pethome.sysDictType.service.IDicTypeService;
import cn.xq.pethome.utils.AjaxUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(value ="tail",description="类型相关的CRUD功能")
@RequestMapping("/tail")
public class DicTailController {
    @Autowired
    private LDicTailService dicTailService;

    @PostMapping("/list")
    @ApiOperation("查询所有数据")
    public AjaxUtil findquery(@RequestBody DicTailQuery dicTailQuery){
        List<DicTail> findall = dicTailService.findquery(dicTailQuery);
        return AjaxUtil.success().setData(findall);
    }

    @PostMapping("/{id}")
    @ApiOperation("根据id查询数据")
    public AjaxUtil findone(@PathVariable("id") Long id){
        DicTail findone = dicTailService.findone(id);
        return AjaxUtil.success().setData(findone);
    }
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除数据")
    public AjaxUtil delete(@PathVariable("id") Long id){
        dicTailService.delete(id);
        return AjaxUtil.success().setMsg("删除成功！");
    }
    @PutMapping("/")
    @ApiOperation("增加与修改")
    public AjaxUtil save(@RequestBody DicTail dicTail){
        if(dicTail.getId()==null){
            dicTailService.insert(dicTail);
            return AjaxUtil.success().setMsg("添加成功!");
        }else {
            dicTailService.update(dicTail);
            return AjaxUtil.success().setMsg("修改成功!");
        }
    }
}
